package com.huajx.tb.codec;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

/**
 * 编码 天波 能龙协议处理
 * 
 * @author xhye
 *
 */
public class NengLongEncoder implements ProtocolEncoder {

	@Override
	public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
		if (message == null) {
			return;
		}

		// 消息类型判断处理
		if (message instanceof String) {
			out.write(IoBuffer.wrap(((String) message).getBytes()));
		} else if (message instanceof byte[]) {
			out.write(IoBuffer.wrap((byte[]) message));
		} else if(message instanceof StringBuilder) {
			out.write(IoBuffer.wrap(((StringBuilder)message).toString().getBytes()));
		} else if(message instanceof StringBuffer) {
			out.write(IoBuffer.wrap(((StringBuffer)message).toString().getBytes()));
		}
	}

	@Override
	public void dispose(IoSession session) throws Exception {

	}

}
